from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n-seg.pt")  # load an official model

common_args = {
    "source": "rtsp://192.168.1.24:8554/Camera458",         # 输入源，可以是视频文件、图片路径或摄像头等
    "stream": True,               # 是否启用流式处理（适用于视频或摄像头输入）
    "show": True,            # 是否实时显示推理结果窗口
    "vid_stride": 5,              # 每 N 帧检测一次，提高性能，适用于视频流
    "imgsz": 3840,                 # 推理时模型输入图像的尺寸，[height, width]
    "conf": 0.3,            # 置信度阈值，低于该值的检测框将被忽略
    "stream_buffer": False,       # 是否启用流缓冲，关闭可降低延迟
    "save": False,                # 是否保存检测结果到文件
    "iou": 0.3,              # IoU（交并比）阈值，用于非极大值抑制
    "half": True,                 # 是否使用半精度推理（float16），加速推理
    "classes": [0],
}

# Predict with the model
results = model.track(**common_args)  # predict on an image

# Access the results
for result in results:
    pass


# def show(self, p=""):
#     """Display an image in a window."""
#     im = self.plotted_img
#     # if platform.system() == "Linux" and p not in self.windows:
#     #     self.windows.append(p)
#     #     cv2.namedWindow(p, cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO)  # allow window resize (Linux)
#     #     cv2.resizeWindow(p, im.shape[1], im.shape[0])  # (width, height)
#     # cv2.imshow(p, im)
    
#     cv2.namedWindow('fullscreen', cv2.WINDOW_NORMAL)
#     cv2.resizeWindow('fullscreen', 960, 480)  # 设置默认大小为全屏窗口大小
#     cv2.imshow("fullscreen", im)
#     cv2.waitKey(300 if self.dataset.mode == "image" else 1)  # 1 millisecond